package model;

/*Date : Feb/15/2012
 * Model source code for DAO obeject.
 * 
 * */
import java.io.File;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;

import org.mybeans.dao.DAOException;
import org.mybeans.factory.BeanTable;
import model.UserDAO;
/*
 * @param:
 * @return:
 * */
public class Model {
	
	//DAO object instances. 
	private UserDAO userDAO;
	private SurveyDAO surveyDAO;
	private QuestionDAO questionDAO;
	private BinaryqDAO binaryqDAO;
	private NumericqDAO numericqDAO;
	private LikertqDAO likertqDAO;
	private MultipleChoiceqDAO multiplechoiceqDAO;
	private ContinuousqDAO continuousqDAO;
	private SocioCognitiveqDAO scqDAO;
	private EntityClassDAO ecDAO;
	private EntityDAO entityDAO;
	private EntityAttributeDAO eaDAO;
	private MailingListDAO mlDAO;
	private MailingListDataDAO mldDAO;
	private Sid_RespondentDAO srDAO;
	private AnswerDAO answerDAO;
	
	public Model(ServletConfig config) throws ServletException {
		String jdbcDriver = null;
		String jdbcURL = null;
		// For CSV file 
		String csvDirStr = config.getInitParameter("csvDir");
		if (csvDirStr != null && csvDirStr.length() > 0) {
			File csvDir = new File(csvDirStr);
			BeanTable.useCSVFiles(csvDir);
		} else {
			// Necessary initial parameter for Mysql database
			jdbcDriver = config.getInitParameter("jdbcDriverName");
			jdbcURL    = config.getInitParameter("jdbcURL");
			BeanTable.useJDBC(jdbcDriver,jdbcURL);
			//connecting to database
		}
		//Create Database acess object		
		try {
			userDAO = new UserDAO();
			surveyDAO = new SurveyDAO();
			questionDAO = new QuestionDAO(jdbcDriver, jdbcURL);
			binaryqDAO = new BinaryqDAO();
			numericqDAO = new NumericqDAO();
			likertqDAO = new LikertqDAO();
			multiplechoiceqDAO = new MultipleChoiceqDAO();
			continuousqDAO = new ContinuousqDAO();
			scqDAO = new SocioCognitiveqDAO();
			ecDAO = new EntityClassDAO();
			entityDAO = new EntityDAO();
			eaDAO = new EntityAttributeDAO(jdbcDriver, jdbcURL);
			mlDAO = new MailingListDAO();
			mldDAO = new MailingListDataDAO();
			srDAO = new Sid_RespondentDAO();
			answerDAO = new AnswerDAO();
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/*get the DAO object method
	@param : null
	@return : DAO object
	*/
	public UserDAO getUserDAO() {
		return userDAO;
	}
	public SurveyDAO getSurveyDAO() {
		return surveyDAO;
	}
	public QuestionDAO getQuestionDAO() {
		return questionDAO;
	}
	public BinaryqDAO getBinaryqDAO() {
		return binaryqDAO;
	}
	public NumericqDAO getNumericqDAO() {
		return numericqDAO;
	}
	public LikertqDAO getLikertqDAO() {
		return likertqDAO;
	}
	public MultipleChoiceqDAO getMultipleChoiceqDAO() {
		return multiplechoiceqDAO;
	}
	public ContinuousqDAO getContinuousqDAO() {
		return continuousqDAO;
	}
	public SocioCognitiveqDAO getSocioCognitiveqDAO() {
		return scqDAO;
	}
	public EntityClassDAO getEntityClassDAO() {
		return ecDAO;
	}
	public EntityDAO getEntityDAO() {
		return entityDAO;
	}
	public EntityAttributeDAO getEntityAttributeDAO() {
		return eaDAO;
	}
	public MailingListDAO getMailingListDAO() {
		return mlDAO;
	}
	public MailingListDataDAO getMailingListDataDAO() {
		return mldDAO;
	}
	public Sid_RespondentDAO getSid_RespondentDAO() {
		return srDAO;
	}
	public AnswerDAO getAnswerDAO() {
		return answerDAO;
	}
}
